package com.can.Service.Impl;

import com.can.Service.EsService;
import com.can.Service.EsTccService;
import com.can.domain.po.Game;
import io.seata.rm.tcc.api.BusinessActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EsTccServiceImpl implements EsTccService {
    @Autowired
    EsService esService;

    @Override
    public boolean esPrepare(Game game,BusinessActionContext context) {
        esService.addGameDoc(game);
         context.getActionContext().put("gameId", game.getId());
        return esService.queryGameDocById(game.getId());
    }
    @Override
    public boolean esCommit(BusinessActionContext context) {

        return true;
    }
    @Override
    public boolean esCancel(BusinessActionContext context) {
        // 删除预留的ES文档
        Long gameId = (Long) context.getActionContext().get("gameId");
        return true;
    }
}